<template>
    <div class="container">
        <header>
            <div class="operate-left" @click="sidebarShow=!sidebarShow">
                <i class="iconfont icon-yonghu"></i>
            </div>
            <div class="operate-right">
                <div class="left">配送社区</div>
                <div class="right" @click="goAddress">
                    <span>{{addressName}}</span>
                    <i class="iconfont icon-jiantou"></i>
                </div>
            </div>
            <div class="operate-date">
                <i class="iconfont">日历</i>
            </div>
        </header>
        <transition name="sidebar">
            <div class="sidebar" v-if="sidebarShow" @click.self="sidebarShow=false">
                <div class="content">
                    <ul>
                        <li>用户名： {{userName}}</li>
                        <li>所在社区： {{userCommunityName}}</li>
                    </ul>
                    <div class="foot" @click="logout">
                        退出登录
                    </div>
                </div>
            </div>
        </transition>
        <div v-for="(order,index) in orders" :key="index">
            <div class="order">
                <div class="order-header">
            <div class="time">
                 {{order.time_end}}
            </div>
            <div class="state">
                {{order.status}}
            </div>
        </div>
        <div class="order-foods" :data="order">
            <div class="food" v-for="(food,index) in order.menus" :key="index">
                <img class="img" :src="'http://47.104.186.142:8000/'+food.pic_url">
                <div class="content">
                    <h3 class="title">{{food.name}}</h3>
                    <div class="describe">{{food.remark}}</div>
                    <div class="price-number">
                        <div class="price">
                            ￥{{food.price}}
                        </div>
                        <div class="number">
                            X{{food.amount}}
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="payment-amount">
            <span class="discount"> 优惠金额：￥ 0.00 </span>
            <span class="amount-paid">
                实付金额： ￥{{order.total_fee/100}}
            </span>
        </div>
        <div class="operate-content">
            <button class="white" type="button" @click="gotoDetail(order.order_num)">订单详情</button>
        </div>
        </div>
        </div>

        <!-- 若无订单则显示此div -->
        <div class="no-data" v-show="showNodata">
            <img class="img" src="../../commom/image/nodata.png" />
            <p class="text">暂无订单</p>
        </div>

    </div>
</template>

<script type="text/ecamscript-6">
import order from "@/components/order/order";
import timeFormat from "@/commom/js/timeFormat";
export default {
  data() {
    return {
      orders: [],
      info: {},
      sidebarShow: false,
      addressName:"",
      userName:"",
      userCommunityName:"",
      showNodata: false
    };
  },
  components: {
    order
  },
  filters: {
    timeFormat(time) {
       let date = new Date(time);
       return timeFormat(date, 'yyyy-MM-dd hh:mm');
    }
  },
  created() {
    // 登陆进来之后存的用户名和用户的社区信息
    this.userName = localStorage.getItem("setUserName");
    this.userCommunityName = localStorage.getItem("setUserCommName");

    if(sessionStorage.getItem("setUserName") == null){
         this.$router.push({
           path: "/login"
        });
    }

    let _this = this;
    // 从后台获取社区配送信息
    this.$axios({
      method: "get",
      url: "http://47.104.186.142:80/delivery/commOne"
    }).then(res => {
      _this.addressName = res.data.data.name;

      if (!localStorage.getItem("setname")) {
        _this.addressName = res.data.data.name;
      } else {
        _this.addressName = localStorage.getItem("setname");
      }
    });

    // 从后台获取订单信息(根据社区名称查询)
    this.$axios({
      method: "get",
      url: "http://47.104.186.142:80/order/queryOrder",
      params: {
        community: localStorage.getItem("setname")
      }
    }).then(res => {
        _this.orders = res.data.data;
        if(res.data.data.length == 0){
            _this.showNodata = true;
        }
    });

  },
  methods: {
    goAddress() {
      this.$router.push({
        path: "/address"
      });
    },
    gotoDetail(order_num) {
     /*  this.$router.push({
        path: `/orderDetail`
      }); */
      this.$router.push({
        path: `/datePicker`
      });
      localStorage.setItem("setOrderNum",order_num);
    },
    logout() {
        localStorage.removeItem("setUserCommName");
        localStorage.removeItem("setUserName");
        sessionStorage.removeItem("setUserName");
        this.$router.push({
            path: "/login"
        });
    }
  }
};
</script>

<style scoped lang="stylus" rel="stylesheet/stylus">
@import '~commom/stylus/mixin';

.container {
    background-color: #f0f0f0;
    overflow: hidden;
    padding-top: 44px;
    min-height: 100vh;

    header {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: 44px;
        background-color: #f20c00;
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0 15px;

        .operate-left {
            extent-click();

            .iconfont {
                color: #ffffff;
                font-size: 20px;
            }
        }

        .operate-right {
            height: 35px;
            width: 260px;
            background-color: #ffffff;
            padding: 0 35px;
            border-radius: 20px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-left: 20px;

            .left {
                font-size: 14px;
                color: #333333;
            }

            .right {
                font-size: 13px;
                color: #999999;

                .iconfont {
                    margin-left: 10px;
                    font-size: 11px;
                }
            }
        }
        .operate-date {
            display: flex;
            justify-content: space-between;
            align-items: center;
            .iconfont {
                color: #fff;
                font-size: 20px;
            }
        }
    }

    .sidebar {
        position: fixed;
        z-index: 10;
        left: 0;
        top: 44px;
        bottom: 0;
        right: 0;
        background-color: rgba(0, 0, 0, 0.3);

        .content {
            position: absolute;
            left: 0;
            top: 0;
            bottom: 0;
            width: 254px;
            background-color: #ffffff;

            ul {
                li {
                    height: 50px;
                    line-height: 50px;
                    padding: 0 15px;
                    color: #333333;
                    font-size: 14px;
                    border-bottom: 1px solid #eee;
                }
            }

            .foot {
                position: absolute;
                bottom: 0;
                left: 0;
                right: 0;
                height: 50px;
                background-color: #f20c00;
                line-height: 50px;
                font-size: 15px;
                color: #fff;
                text-align: center;
            }
        }
    }

    .order {
        margin: 0 0 10px;
        background-color: #ffffff;
    }
}

.sidebar-enter-active, .sidebar-leave-active {
    transition: all 0.3s;
}

.sidebar-enter, .sidebar-leave-to {
    opacity: 0;
}
.order {
    padding: 0 15px;

    .order-header {
        height: 45px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        font-size: 14px;

        .time {
            color: #333333;
        }

        .state {
            color: #f20c00;
        }
    }

    .order-foods {
        .food {
            padding: 10px 0;
            border-top: 1px solid #eeeeee;
            display: flex;

            .img {
                flex: 0 0 105px;
                width: 105px;
                height: 70px;
                margin-right: 15px;
            }

            .content {
                flex: 1;

                .title {
                    color: #333;
                    font-size: 15px;
                    font-weight: bold;
                }

                .describe {
                    color: #666;
                    font-size: 13px;
                    line-height: 16px;
                    height: 32px;
                    line-hidden(2);
                    margin: 5px 0;
                }

                .price-number {
                    display: flex;
                    justify-content: space-between;
                    align-items: center;

                    .price {
                        color: #f20c00;
                        font-size: 12px;
                    }

                    .number {
                        font-size: 13px;
                        color: #333333;
                    }
                }
            }
        }
    }

    .payment-amount {
        overflow: hidden;
        height: 45px;
        border-bottom: 1px solid #eeeeee;
        border-top: 1px solid #eeeeee;
        line-height: 45px;
        color: #333333;
        font-size: 13px;

        .discount {
            margin-right: 30px;
        }
    }

    .operate-content {
        display: flex;
        justify-content: flex-end;
        padding: 10px 0;

        button {
            height: 30px;
            width: 91px;
            text-align: center;
            border: none;
            outline: none;
            border-radius: 20px;
            font-size: 13px;

            &.red {
                background-color: #f20c00;
                color: #ffffff;
            }

            &.white {
                margin-left: 16px;
                background-color: #ffffff;
                border: 1px solid #333333;
                color: #333333;
            }
        }
    }
}
.no-data{
    margin: 0 auto;
    max-width: 90%;
    padding: 40px 0;
}
    .img{
        margin: 0 auto;
        display: block;
        max-width: 100%;
    }
    .text{
        text-align: center;
        font-size: 18px;
        color: #666;
        padding: 20px 20px 0 0;
    }
</style>
